#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
	int maximalSquare(vector<vector<char>>& matrix) {
		if (matrix.empty()) return 0;
		vector<int> dp(matrix[0].size(), 0);
		int prev = 0, maxsize = 0;
		for (int i = 0; i < matrix.size(); ++i) {
			for (int j = 0; j < matrix[i].size(); ++j) {
				int tmp = dp[j];
				if (matrix[i][j] == '1') {
					if (j > 0) {
						dp[j] = (dp[j] > dp[j - 1]) ? (dp[j - 1] > prev ? prev : dp[j - 1]) : (dp[j] > prev ? prev : dp[j]);
						dp[j] += 1;
					}
					else {
						dp[j] = 1;
					}
					maxsize = maxsize < dp[j] ? dp[j] : maxsize;
				}
				else {
					dp[j] = 0;
				}
				prev = tmp;
			}
		}
		return maxsize*maxsize;
	}
};

int main() {
	vector<vector<char>> vecs;
	for (int i = 0; i < 3; ++i) {
		vector<char> vec_m;
		for (int j = 0; j < 4; ++j) {
			vec_m.push_back('1');
		}
		vecs.push_back(vec_m);
	}
	Solution* s = new Solution();
	int b = s->maximalSquare(vecs);
	cout << b << endl;
	return 0;
}